package psn.zjk.springboot.web.config;

import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import psn.zjk.springboot.web.interceptor.PermissionInterceptor;
import psn.zjk.springboot.web.servlet.i18n.MyLocaleResolver;

/** 一但容器包含WebMvcConfigurationSupport组件（等同@EnableWebMvc），自动配置失效 张骏凯 2020年1月31日 */
//@Component
public class WebDIYConfig extends WebMvcConfigurationSupport {

    @Override public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new PermissionInterceptor()).addPathPatterns("/**")
                .excludePathPatterns("/index.html", "/", "/login");
    }

    @Override public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("dashboard");
        registry.addViewController("/index.html").setViewName("dashboard");
    }

    @Override protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("/static,/public,/i18n,/messages,/resources");
    }

    @Bean public LocaleResolver localeResolver() {
        return new MyLocaleResolver();
    }

}
